package online.inote.modules.article.controller;

import java.util.Map;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import online.inote.common.core.BaseController;
import online.inote.common.core.Page;
import online.inote.common.utils.ResultFactory;
import online.inote.common.utils.ResultFactory.ResultEnum;
import online.inote.common.utils.StringUtils;
import online.inote.modules.article.entity.ArticleEntity;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * <p>
 * Desc: 文章Controller
 * </p>
 *
 * @author Sui
 * @created: 2017年12月3日 上午12:49:28
 * @version 1.0
 */
@RestController
@RequestMapping(value = "article")
public class ArticleController extends BaseController<ArticleEntity> {

	/**
	 * <p>
	 * Desc: 文章管理列表
	 * </p>
	 *
	 * @author XQF SUI
	 * @created 2017年12月4日 上午10:58:36
	 * @param request
	 * @param page
	 * @param type
	 * @param pageNumer
	 * @return
	 */
	@RequestMapping(value = "getPage", method = RequestMethod.POST)
    public Map<String, Object> getPage(Page<ArticleEntity> page, ArticleEntity article) {
    	
		Example example = new Example(ArticleEntity.class);
        Criteria criteria = example.createCriteria();
        
        if (StringUtils.isNotBlank(article.getTitle())) {
        	criteria.andLike("title", "%" + article.getTitle() + "%");
        }
        
        if (article.getType() != null) {
            criteria.andEqualTo("type", article.getType());
        }
        
        if (article.getCreateTime() != null) {
        	criteria.andGreaterThanOrEqualTo("createTime", article.getCreateTime());
        }
        
        // 根据创建时间倒序
        example.orderBy("operateTime").desc();
        // 开始分页查询
        service.selectPageByExample(example, page);
        
        return ResultFactory.createResultMap(ResultEnum.SUCCESS, page);
    }   
}